console.log("background.js loaded start");
// var script = document.createElement("script");
// script.type = "text/javascript";
// script.src = chrome.extension.getURL("js/jquery-2.2.4.min.js");
// (document.head || document.documentElement).appendChild(script);
//
// $("body").append("<div id='kdc' class='loader-triangle'>孔德超</div>");
let windowsPortMap = {};
chrome.runtime.onMessage.addListener((message, sender, sendResponse)=> {
    console.log("background.js onMessage",message);
    if (message.type == "register") {
        windowsPortMap[message.windowId] = sender.tab.id;
        console.log("register",windowsPortMap);
    }else if (message.type == "toBackgroundToWindowById") {
        let targetPort = windowsPortMap[message.windowId];
        if (targetPort) {
            chrome.tabs.sendMessage(targetPort, message);
        }
    }
    sendResponse({code: 200, msg: "收到消息"});
})
console.log("background.js loaded end");

